package com.waylau.spring.boot.blog.repository;

import com.waylau.spring.boot.blog.domain.Genre;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import com.waylau.spring.boot.blog.domain.Blog;
import com.waylau.spring.boot.blog.domain.Catalog;
import com.waylau.spring.boot.blog.domain.User;

import java.util.Collection;
import java.util.List;

/**
 * Blog 仓库.
 *
 * @since 1.0.0 2017年4月7日
 * @author <a href="https://waylau.com">Way Lau</a> 
 */
public interface BlogRepository extends JpaRepository<Blog, Long>{
	/**
	 * 根据用户名分页查询用户列表（最新）
	 * 由 findByUserAndTitleLikeOrTagsLikeOrderByCreateTimeDesc 代替，可以根据标签进行查询
	 * @param user
	 * @param title
	 * @param pageable
	 * @return
	 * @see findByTitleLikeOrTagsLikeAndUserOrderByCreateTimeDesc
	 */
	@Deprecated
	Page<Blog> findByUserAndTitleLikeAndStatusOrderByCreateTimeDesc(User user, String title,Integer status, Pageable pageable);
	
	/**
	 * 根据用户名分页查询用户列表
	 * @param user
	 * @param title
	 * @param sort
	 * @param pageable
	 * @return
	 */
	Page<Blog> findByUserAndTitleLikeAndStatus(User user, String title,Integer status, Pageable pageable);
	
	/**
	 * 根据用户名分页查询用户列表
	 * @param user
	 * @param title
	 * @param sort
	 * @param pageable
	 * @return
	 */
	Page<Blog> findByTitleLikeAndUserOrTagsLikeAndUserAndStatusOrderByCreateTimeDesc(String title, User user, String tags, User user2,Integer status, Pageable pageable);
	/**
	 * 根据用户名分页查询用户列表
	 * @param user
	 * @param title
	 * @param sort
	 * @param pageable
	 * @return
	 */
	Page<Blog> findByCatalogAndStatus(Catalog catalog, Integer Status,Pageable pageable);

	/**
	 * 查找指定ids 分页
	 * @param c
	 * @param pageable
	 * @return
	 */
    Page<Blog> findByIdInAndStatus(Collection c, Integer status,Pageable pageable);

	/**
	 * 获取某类下浏览量前4
	 * @param genre
	 * @return
	 */
	List<Blog> findTop4ByGenreAndStatusOrderByReadSizeDesc(Genre genre,Integer status);

	/**
	 * 获取某类下浏览量前3
	 * @param genre
	 * @return
	 */
	List<Blog> findTop3ByGenreAndStatusOrderByReadSizeDesc(Genre genre,Integer status);

	/**
	 * 获取某类下浏览量前2
	 * @param genre
	 * @return
	 */
	List<Blog> findTop2ByGenreAndStatusOrderByReadSizeDesc(Genre genre,Integer status);

	/**
	 * 获取某类下浏览量前1
	 * @param genre
	 * @return
	 */
	List<Blog> findTop1ByGenreAndStatusOrderByReadSizeDesc(Genre genre,Integer status);

	Page<Blog> findByTitleLikeAndStatusOrderByCreateTimeDesc(String title,Integer status, Pageable pageable);

	Page<Blog> findByTitleLikeAndStatusOrderByCreateTimeAsc(String title,Integer status, Pageable pageable);


	Blog findByIdAndStatus(Long id,Integer status);

	List<Blog> findByStatus(Integer status);



}
